//
//  DownloadManager.m
//  Leisure
//
//  Created by 大展 on 16/7/6.
//  Copyright © 2016年 大展. All rights reserved.
//

#import "DownloadManager.h"

@interface DownloadManager ()<DownloadDelegate>

@property (nonatomic, strong)NSMutableDictionary *dic;

@end

@implementation DownloadManager


+ (instancetype)sharedManager {

    static DownloadManager *handle = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{

        handle = [[DownloadManager alloc]init];
    });
    return handle;
}

- (NSMutableDictionary *)dic {

    if (!_dic) {

        _dic = [NSMutableDictionary dictionary];
    }
    return _dic;
}

- (Download *)addDownloadWithUrl:(NSString *)url {


    Download *download = [[Download alloc]initWithUrl:url];
    download.delegate = self;
    [download startDownload];

    [self.dic setObject:download forKey:url];

    return download;
}


- (Download *)findDownloadWithUrl:(NSString *)url {

    return self.dic[url];
}


- (void)didFinshDownload:(NSString *)url {

    [self.dic removeObjectForKey:url];
}

@end
